Written by: Prograph International (Terry Kilshaw)
Contents: Check Text.pgs
Check Text.ReadMe
Needs Prograph Extensions:
Math Primitives
More Primitives
Primitives
Needs Libraries to Compile:
SCLibrary 2.6
Library 2.6
Description
-----------
A text item class to simplify the checking of input values before any other text item or Scroll List item is selected, or the window is closed. This allows the programmer to give feedback to users on a field by field basis when they are filling in a form on screen.
The Check Text class is designed to be easily extended with new check methods. Three example check methods are provided - "type", "range" and "length".
The Check Text Example in this file displays a simple entry form and performs appropriate checks on fields.
How To Use In Your Program
-------------------------------
The Check Text class should be selectively loaded as a subclass of "Edit Text" and the two methods with names of the form classname/methodname should be moved to their target classes. Remember to change their names back to just methodname. The other methods remain in this class.
To use, create window items of type "Check Text". Attr "checks" should contain a list of method names which will be called to do the checks. Attr "limits" should contain a list of lists. Each list holds the limits information for its corresponding check method - that is one list for each method name given in attr "checks". ( Remember that you can access the attributes of an instance of a window item in the window editor by pressing the command-option-shift keys while clicking on the item. )
For example the first field in a form might be a name which must be a string which is 1 to 32 characters long. Set attr "checks" to ( "//type" "//length" ) and attr "limits" to ( (string) (1 32 ) ).
The second field might be a year of birth, an integer between 1900 and 1999 say. Set attr "checks" to ( "//type" "//range" ) and attr "limits" to ( (integer) (1900 1999 ) ).
Obviously you can write your own check methods to put in the "checks" list. A check method has one input, ( the instance of "Check Text" ), and no outputs. It should either succeed or fail. Three example check methods are provided - "type", "range" and "length". If a check method succeeds everything proceeds as usual. If it fails then it beeps and an error message is given. The programmer may wish to change this behaviour to
suit their own application.
A check is made, when the selected item in a window is a "Check Text", by a call to "Check Text/do check". This is called from Window/selected item when the selected item is about to be set; if the check fails, the next item is not selected. The programmer should call "Window/check & close" to close any window which contains "Check Text" items if checks should be made, but should call the normal "Window/close" method if no checks are to be made. Otherwise it would be impossible to cancel a window unless its check text fields had valid data in them!